package com.xiaolanshu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xiaolanshu.entity.Collection;
import com.xiaolanshu.entity.Praise;
import com.xiaolanshu.mapper.CollectionMapper;
import com.xiaolanshu.service.CollectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CollectionServiceImpl  implements CollectionService {
    @Autowired
    private CollectionMapper collectionMapper;

    //根据用户id和笔记id查找收藏信息
    @Override
    public Collection findCollection(Long userId, Long noteId) {
        LambdaQueryWrapper<Collection> lqw = new LambdaQueryWrapper<>();
        lqw.eq(Collection::getUserId,userId).eq(Collection::getNoteId,noteId);
        return collectionMapper.selectOne(lqw);
    }
    //保存收藏信息
    @Override
    public void saveCollection(Collection collectionNew) {
        collectionMapper.insert(collectionNew);
    }
    //更新收藏信息
    @Override
    public void updateById(Collection collection) {
        collectionMapper.updateById(collection);
    }
    //根据用户id查找收藏的笔记
    @Override
    public List<Collection> findCollection(Long userId) {
        LambdaQueryWrapper<Collection> lqw = new LambdaQueryWrapper<>();
        //构造查询条件，根据用户id查询，且收藏未被取消
        lqw.eq(Collection::getUserId,userId).eq(Collection::getCollection,1);
        return collectionMapper.selectList(lqw);
    }
}
